package com.juanjuan.myproject.config;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zhaocun
 * @Date: 2023/10/26/17:06
 * @Description:线程池
 */
public class ThreadPoolConfig {

    private static ThreadPoolExecutor executor;

    public static ThreadPoolExecutor getExecutor(){
        if (executor==null ||executor.isTerminated()){
            executor=new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(100), new ThreadFactory() {
                @Override
                public Thread newThread(@NotNull Runnable r) {
                    return new Thread(r,"CustomThread");
                }
            });

        }
        return executor;
    }
}
